]>
Commit | Line | Data |
---|---|---|
77d0155b | 1 | import Combine |
5e8ff485 RBR |
2 | import CoreData |
3 | import CoreGraphics | |
4 | import SwiftUI | |
5 | ||
6 | struct MapRenderView: View { | |
7 | ||
75a0e450 | 8 | @Binding var content: String |
fdb4633d RBR |
9 | @Binding var evolution: StageType |
10 | ||
11 | var stage: Stage { | |
12 | Stage.stages(evolution) | |
13 | } | |
75a0e450 RBR |
14 | |
15 | @State var parsedMap: ParsedMap = ParsedMap.empty | |
5e8ff485 RBR |
16 | |
17 | let mapSize = CGSize(width: 1300.0, height: 1000.0) | |
18 | ||
fdb4633d | 19 | let lineWidth = CGFloat(0.5) |
5e8ff485 RBR |
20 | let vertexSize = CGSize(width: 25.0, height: 25.0) |
21 | let padding = CGFloat(30.0) | |
22 | ||
5e8ff485 RBR |
23 | var body: some View { |
24 | ZStack(alignment: .topLeading) { | |
25 | ||
26 | Path { path in | |
27 | path.addRect( | |
28 | CGRect( | |
29 | x: -padding, y: -padding, width: mapSize.width + padding * 2, | |
77d0155b | 30 | height: mapSize.height + padding * 4)) |
fdb4633d | 31 | }.fill(.white) |
5e8ff485 RBR |
32 | |
33 | MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages) | |
34 | MapAxes( | |
fdb4633d RBR |
35 | mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages) |
36 | MapEdges( | |
37 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges) | |
38 | MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers) | |
39 | MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices) | |
5e8ff485 RBR |
40 | MapOpportunities( |
41 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, | |
42 | opportunities: parsedMap.opportunities) | |
fdb4633d RBR |
43 | MapNotes( |
44 | mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes) | |
5e8ff485 RBR |
45 | }.frame( |
46 | width: mapSize.width, | |
77d0155b | 47 | height: mapSize.height + 2 * padding, alignment: .topLeading |
75a0e450 RBR |
48 | ).onAppear { |
49 | self.parsedMap = Map.parse(content: content) | |
50 | }.padding(padding).onChange(of: content) { newState in | |
51 | self.parsedMap = Map.parse(content: newState) | |
52 | } | |
5e8ff485 RBR |
53 | } |
54 | } | |
55 | ||
56 | struct MapRenderView_Previews: PreviewProvider { | |
57 | static var previews: some View { | |
75a0e450 | 58 | MapRenderView( |
fdb4633d | 59 | content: Binding.constant(""), evolution: Binding.constant(StageType.general) |
75a0e450 | 60 | ).environment( |
5e8ff485 RBR |
61 | \.managedObjectContext, PersistenceController.preview.container.viewContext) |
62 | } | |
63 | } |